from django.db import models
import fontfield
import datetime

class Tag(models.Model):
    name = models.CharField(max_length=30,blank=False)

    def __unicode__(self):
        return self.name

class Category(models.Model):
    name = models.CharField(max_length=30,blank=False)
    slug = models.SlugField()
    description = models.TextField()
    created = models.DateTimeField(default=datetime.datetime.now)
    rating = models.PositiveIntegerField(default=0)

    class Meta:
        ordering = ['created']
        verbose_name_plural = "categories"

    def __unicode__(self):
        return self.name

    @models.permalink
    def get_absolute_url(self):
        return ('fontrender.converter.views.converter', (), {'slug_category': self.slug})

class Font(models.Model):
    name = models.CharField(max_length=30,blank=False)
    font_file = fontfield.FontField(upload_to='fonts',blank=False)
    slug = models.SlugField()
    tags = models.ManyToManyField(Tag,blank=False)
    category = models.ForeignKey(Category,blank=False)
    created = models.DateTimeField(default=datetime.datetime.now)
    rating = models.PositiveIntegerField(default=0)

    def __unicode__(self):
        return self.name

    @models.permalink
    def get_absolute_url(self):
        return ('fontrender.converter.views.converter', (),
                {'slug_category': self.category.slug, 'slug_font': self.slug})
